package com.kk.single;

/**
 * 懒汉式
 * 静态内部类
 *
 * @author 王志强
 * @date 2021-12-09
 */
public class Singleton4 {

    private Singleton4() {
    }

    public static Singleton4 getInstance() {
        return SingletonInstance.INSTANCE;
    }

    public static void main(String[] args) {

        for (int i = 0; i < 33; i++) {
            new Thread(() -> {
                Singleton4 instance = Singleton4.getInstance();
                System.out.println("instance =  " + instance + "\n" + instance.hashCode());
            }).start();
        }

    }

    private static class SingletonInstance {
        private static final Singleton4 INSTANCE = new Singleton4();
    }
}
